package @controllerPackage@;

/**
 * Class which encapsulates static string operations
 * created: 08.10.2008
 *
 * @author Michal Rost
 */
public class StringUtils {

  /**
   * Inserts parameter to string
   *
   * @param pos position (number) of parameter
   * @param param value of parameter
   * @param original original string
   * @return string with parameter
   */
  public static String insertParam(int pos, String param, String original) {
    return original.replace("{".concat(Integer.toString(pos)).concat("}"), param);
  }

  /**
   * Inserts parameter to string
   *
   * @param params parameters values
   * @param original original string
   * @return string with parameters
   */
  public static String insertParams(String[] params, String original) {
    String result = original;
    for (int i = 0; i < params.length; i++) {
      result = insertParam(i, params[i], result);
    }
    return result;
  }

  /**
   * Changes first letter of string to upper case
   *
   * @param word original string
   * @return word with capital first letter
   */
  public static StringBuffer firstToUpper(String word) {
    StringBuffer tmp = new StringBuffer(word);
    tmp.setCharAt(0, Character.toUpperCase(tmp.charAt(0)));
    return tmp;
  }

  /**
   * Changes first letter of string to lower case
   *
   * @param word original string
   * @return word with small first letter
   */
  public static StringBuffer firstToLower(String word) {
    StringBuffer tmp = new StringBuffer(word);
    tmp.setCharAt(0, Character.toLowerCase(tmp.charAt(0)));
    return tmp;
  }

  /**
   * Converts string to date
   *
   * @param str string to be parsed
   * @return date
   * @throws java.text.ParseException
   */
  public static java.util.Date strToDate(String str) throws java.text.ParseException {
    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat();
    return (java.util.Date) formatter.parse(str);
  }

  /**
   * Converts date to string
   *
   * @param date date to be converted
   * @return string
   */
  public static String dateToStr(java.util.Date date) {
    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat();
    return formatter.format(date);
  }
}
